"""
求指定层的元素个数
"""
def judge(l, c, n):
    sum1 = 0
    for i in l:
        if type(i) == list:
            sum1 += judge(i, c+1, n)
        elif type(i) == tuple:
            sum1 += judge(i, c+1, n)
        elif type(i) == int and c == n:
            sum1 += 1
    return sum1
list1 = list(eval(input()))
n = int(input())
print(judge(list1, 1, n))
